Global Index
HTML5 JS API Index > File API Tutorials & Specs

FileReader

Extends EventTarget.

This interface provides methods to read File objects or Blob objects into memory, and to access the data from those Files or Blobs using progress events and event handler attributes; it inherits from EventTarget [DOM4]. It is desirable to read data from file systems asynchronously in the main thread of user agents.

Properties
const unsigned short
DONE = 2
The entire File or Blob has been read into memory, OR a file error occurred during read, OR the read was aborted using abort(). The FileReader is no longer reading a File or Blob. If readyState is set to DONE it means at least one of the read methods have been called on this FileReader.
const unsigned short
EMPTY = 0
The FileReader object has been constructed, and there are no pending reads. None of the read methods have been called. This is the default state of a newly minted FileReader object, until one of the read methods have been called on it.
const unsigned short
LOADING = 1
A File or Blob is being read. One of the read methods is being processed, and no error has occurred during the read.
DOMError?
error
The error attribute of the FileReader object must return a DOMError object [DOM4] of the most appropriate type from the table below if there has been an error, and otherwise returns null.
EventHandleronabort
EventHandleronerror
EventHandleronload
EventHandleronloadend
EventHandleronloadstart
EventHandleronprogress
unsigned short
readyState
The FileReader object can be in one of 3 states.
(DOMString or ArrayBuffer)
result
On getting, the result attribute returns a Blob's data as a DOMString, or as an ArrayBuffer [TypedArrays], or null, depending on the read method that has been called on the FileReader, and any errors that may have occurred.
Constructor
FileReader()
Operations
voidabort()
void
readAsArrayBuffer(Blob blob)
When the readAsArrayBuffer(blob) method is called, the user agent must run the steps below (unless otherwise indicated).
void
readAsDataURL(Blob blob)
When the readAsDataURL(blob) method is called, the user agent must run the steps below (unless otherwise indicated).
void
readAsText(Blob blob, optional DOMString label)
When the readAsText(blob, label) method is called (the label argument is optional), the user agent must run the steps below (unless otherwise indicated).